package com.example.ggg;

import com.example.ggg.anno.MyAnnotation;
import com.example.ggg.event.MyEventPublisher;
import com.example.ggg.exception.SpecificException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Demo {
    @GetMapping("/show")
    public String show() {
        System.out.println("show start");
        return "Hello,world";

    }

    @GetMapping("/test")
    @MyAnnotation(name = "开发喵")
    public String testMethod() {
        return "Test Method";
    }

    @Autowired
    private MyEventPublisher myEventPublisher;


    @GetMapping("/trigger-event")
    public String triggerEvent() {
        myEventPublisher.publishEvent();
        return "Event triggered";
    }

    @GetMapping("/tests")
    public String test() {
        if (9 / 0 == 0) {
            throw new SpecificException("Something went wrong!");
        }
        return "Success";
    }
}
